package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.happy.cat.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import com.happy.cat.project.system.domain.UserChatroomApply;
import com.happy.cat.project.system.service.IUserChatroomApplyService;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.common.utils.poi.ExcelUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.happy.cat.framework.web.page.TableDataInfo;

/**
 * 聊天室申请Controller
 *
 * @author verne
 * @date 2020-08-29
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/userChatroomApply" )
@Api("聊天室申请 API")
public class UserChatroomApplyController extends BaseController {

    private final IUserChatroomApplyService iUserChatroomApplyService;

    /**
     * 查询聊天室申请列表
     */
    @ApiOperation(value = "查询聊天室申请列表",notes = "查询聊天室申请列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:userChatroomApply:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserChatroomApply userChatroomApply)
    {
        startPage();
        LambdaQueryWrapper<UserChatroomApply> lqw = new LambdaQueryWrapper<UserChatroomApply>();
        if (StringUtils.isNotBlank(userChatroomApply.getCode())){
            lqw.eq(UserChatroomApply::getCode ,userChatroomApply.getCode());
        }
        if (userChatroomApply.getAccountId() != null){
            lqw.eq(UserChatroomApply::getAccountId ,userChatroomApply.getAccountId());
        }
        if (userChatroomApply.getChatroomTypeId() != null){
            lqw.eq(UserChatroomApply::getChatroomTypeId ,userChatroomApply.getChatroomTypeId());
        }
        if (StringUtils.isNotBlank(userChatroomApply.getPhoto())){
            lqw.eq(UserChatroomApply::getPhoto ,userChatroomApply.getPhoto());
        }
        if (StringUtils.isNotBlank(userChatroomApply.getReason())){
            lqw.eq(UserChatroomApply::getReason ,userChatroomApply.getReason());
        }
        if (userChatroomApply.getCounts() != null){
            lqw.eq(UserChatroomApply::getCounts ,userChatroomApply.getCounts());
        }
        if (userChatroomApply.getStatus() != null){
            lqw.eq(UserChatroomApply::getStatus ,userChatroomApply.getStatus());
        }
        if (userChatroomApply.getApplyTime() != null){
            lqw.eq(UserChatroomApply::getApplyTime ,userChatroomApply.getApplyTime());
        }
        if (StringUtils.isNotBlank(userChatroomApply.getApplyBy())){
            lqw.eq(UserChatroomApply::getApplyBy ,userChatroomApply.getApplyBy());
        }
        if (StringUtils.isNotBlank(userChatroomApply.getApplyText())){
            lqw.eq(UserChatroomApply::getApplyText ,userChatroomApply.getApplyText());
        }
        List<UserChatroomApply> list = iUserChatroomApplyService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出聊天室申请列表
     */
    @ApiOperation(value = "导出聊天室申请列表",notes = "导出聊天室申请列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userChatroomApply:export')" )
    @Log(title = "聊天室申请" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(UserChatroomApply userChatroomApply) {
        LambdaQueryWrapper<UserChatroomApply> lqw = new LambdaQueryWrapper<UserChatroomApply>(userChatroomApply);
        List<UserChatroomApply> list = iUserChatroomApplyService.list(lqw);
        ExcelUtil<UserChatroomApply> util = new ExcelUtil<UserChatroomApply>(UserChatroomApply. class);
        return util.exportExcel(list, "userChatroomApply" );
    }

    /**
     * 获取聊天室申请详细信息
     */
    @ApiOperation(value = "获取聊天室申请详细信息",notes = "获取聊天室申请详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userChatroomApply:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iUserChatroomApplyService.getById(id));
    }

    /**
     * 新增聊天室申请
     */
    @ApiOperation(value = "新增聊天室申请",notes = "新增聊天室申请",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userChatroomApply:add')" )
    @Log(title = "聊天室申请" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserChatroomApply userChatroomApply) {
        return toAjax(iUserChatroomApplyService.save(userChatroomApply) ? 1 : 0);
    }

    /**
     * 修改聊天室申请
     */
    @ApiOperation(value = "修改聊天室申请",notes = "修改聊天室申请",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userChatroomApply:edit')" )
    @Log(title = "聊天室申请" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserChatroomApply userChatroomApply) {
        return toAjax(iUserChatroomApplyService.updateById(userChatroomApply) ? 1 : 0);
    }

    /**
     * 删除聊天室申请
     */
    @ApiOperation(value = "删除聊天室申请",notes = "删除聊天室申请",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userChatroomApply:remove')" )
    @Log(title = "聊天室申请" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iUserChatroomApplyService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
